package cn.xiuxian.util;

import java.sql.*;

@SuppressWarnings("all")
public class JdbcUtil {

    private  static  String  URL = DbConfigUtil.getValue("url");
    private  static  String  USERNAME = DbConfigUtil.getValue("username");
    private  static  String  PASSWORD = DbConfigUtil.getValue("password");

    public  static   Connection  getConnection() throws SQLException {

        Connection connection = DriverManager.getConnection(URL,USERNAME,PASSWORD);
        return  connection;
    }

    public  static   void   closeConnection(Connection connection, Statement statement){

        if(statement != null){
            try {
                statement.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
       if(connection != null){
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

    }

    public  static   void   closeConnection(Connection connection, Statement statement, ResultSet resultSet){
        if (resultSet != null){
            try {
                resultSet.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        if(statement != null){
            try {
                statement.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(connection != null){
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

    }
}
